<?php
/**
 *+------------------
 * Lflow
 *+------------------
 * Copyright (c) 2023~2030 gitee.com/liu_guan_qing All rights reserved.本版权不可删除，侵权必究
 *+------------------
 * Author: Mr.April(405784684@qq.com)
 *+------------------
 */
declare (strict_types=1);

namespace lflow\entity;

use lflow\model\ProcessModel;

class Process
{
    /**
     * 主键ID
     */
    private string $id;

    /**
     * 版本
     */
    private int $version;

    /**
     * 流程定义名称
     */
    private string $name;

    /**
     * 流程定义显示名称
     */
    private string $display_name;

    /**
     * 流程定义类型（预留字段）
     */
    private string $type;

    /**
     * 当前流程的实例url（一般为流程第一步的url）
     * 该字段可以直接打开流程申请的表单
     */
    private ?string $instance_url;

    /**
     * 是否可用的开关
     */
    private int $state;

    /**
     * 创建时间
     */
    private string $create_time;

    /**
     * 创建人
     */
    private string|null $creator;

    /**
     * 流程定义模型
     */
    private ProcessModel $model;

    /**
     * 流程定义json
     */
    private string|null $content;

    public function getPk(): string
    {
        return $this->pk ?? 'id';
    }

    /**
     * getName
     *
     * @return string
     */
    public function getName(): string
    {
        return $this->name ?? '';
    }

    /**
     * setName
     *
     * @param string $name
     */
    public function setName(string $name): void
    {
        $this->name = $name;
    }

    public function getDisplayName(): string
    {
        return $this->display_name ?? '';
    }

    public function setDisplayName(string $displayName): void
    {
        $this->display_name = $displayName;
    }

    public function getType(): string
    {
        return $this->type ?? '';
    }

    public function setType(string $type): void
    {
        $this->type = $type;
    }

    public function getState(): int
    {
        return $this->state ?? 2;
    }

    public function setState(int $state)
    {
        $this->state = $state;
    }

    public function getId(): string
    {
        return $this->id ?? '';
    }

    public function setId(string $id)
    {
        $this->id = $id;
    }

    public function getModel(): ?ProcessModel
    {
        return $this->model ?? null;
    }

    /**
     * setter name/displayName/instanceUrl
     *
     * @param processModel
     */
    public function setModel($processModel)
    {
        $this->model        = $processModel;
        $this->name         = $processModel->getName();
        $this->display_name = $processModel->getDisplayName();
        $this->instance_url = $processModel->getInstanceUrl();
    }

    public function getInstanceUrl(): string
    {
        return $this->instance_url ?? '';
    }

    public function setInstanceUrl(string $instanceUrl)
    {
        $this->instance_url = $instanceUrl;
    }

    public function getContent(): string
    {
        return $this->content ?? '';
    }

    public function setContent($content): void
    {
        $this->content = $content;
    }

    public function getVersion(): int
    {
        return $this->version ?? 0;
    }

    public function setVersion(int $version): void
    {
        $this->version = $version;
    }

    public function getCreateTime(): string
    {
        return $this->create_time ?? '';
    }

    public function setCreateTime(string $createTime): void
    {
        $this->create_time = $createTime;
    }

    public function getCreator(): string
    {
        return $this->creator ?? '';
    }

    public function setCreator(string $creator): void
    {
        $this->creator = $creator;
    }

    public function toString(): string
    {
        return json_encode(get_object_vars($this));

    }

    public function toArray(): array
    {
        return get_object_vars($this);
    }

}